<%--
  Created by IntelliJ IDEA.
  Date: 2022/5/13
  Time: 11:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" +request.getServerPort() +
            request.getContextPath() + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <title>Title</title>
</head>
<body>
<input id="PageContext" type="hidden" value="${pageContext.request.contextPath}" />
<div style="padding: 15px;">
    <div class="panel-body">
        <table class="table table-hover">
            <thead>
            <h1></h1>
            <tr>
                <td>诊断时间</td>
                <td>备注</td>
            </tr>
            </thead>
            <tbody id="information">

            </tbody>
        </table>
    </div>
</div>
</body>
<script>
    $(function () {
        LoadAccessData();
    })
    //ajax请求
    function LoadAccessData() {
        $.ajax({
            url: $("#PageContext").val()+"/getVisit",
            type: "get",
            dataType: "json",
            success: function (data) {
                //清除旧的数据
                $("#information").html("");
                //添加新的数据
                $.each(data, function (i, n) {
                    $("#information").append("<tr>")
                        .append("<td>" + n.id + "</td>")
                        .append("<td>" + n.name + "</td>")
                        .append("<td>" + n.phone + "</td>")
                        .append("<td>" + n.time + "</td>")
                        .append("<td>" + "<button onclick='javascript:return GetCustomer("+n.customerId+")' class='layui-btn layui-btn-sm layui-btn-primary'><i class='layui-icon layui-icon-list' style='font-size: 30px; color: #1E9FFF;'></i></button></td>")
                        .append("<td><button onclick='javascript:return Del("+n.id+")' class='layui-btn layui-btn-sm layui-btn-primary'><i class='layui-icon layui-icon-delete' style='font-size: 30px; color: red;'></i></button></td>")
                        .append("</tr>")
                });
            },
        })
    }
    //ajax 删除请求
    function Del(id){
        var msg = "确认删除？";
        if (confirm(msg)==true){
            // alert(id+"--"+pageNum)
            id=parseInt(id)
            // alert(id)
            $.ajax({
                url: $("#PageContext").val()+"/deleteAccess",
                type: "post",
                data : {
                    id:id
                },
                success: function () {
                    //情况旧数据
                    LoadAccessData();
                    layer.msg('删除成功');
                }
            })
        }else{
            return false;
        }
    }
    function GetCustomer(id){
        id=parseInt(id)
        $.ajax({
            url: $("#PageContext").val()+"/getCustomer",
            type: "get",
            data : {
                id:id
            },
            success: function (data) {
                console.log(data.name)
                layer.open({
                    title: '主人信息',
                    // area: ['500px', '300px'],
                    content:
                        "编号:"+data.id+"</br>"+
                        "主人:"+data.name+"</br>"+
                        "宠物:"+data.petName+"</br>"+
                        "电话:"+data.phone+"</br>"+
                        "居住地址:"+data.address+"</br>"+
                        "登记时间:"+data.createTime+"</br>"
                });
            }
        })

    }
</script>
</html>
